package wechat.base.snd.domain;

import java.io.File;
import org.apache.log4j.Logger;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import wechat.base.snd.QRCode;
import wechat.base.snd.QRCodeManager;
import wechat.base.snd.WCServiceApp;
import wechat.base.snd.util.ExecGet;

@SuppressWarnings("all")
public class SqrCode {
  private static Logger logger = Logger.getLogger("SqrCode");
  
  public static File getSqrcodeFile(final WCServiceApp app, final String info) {
    File _xtrycatchfinallyexpression = null;
    try {
      File _xblockexpression = null;
      {
        final QRCode qrcode = new QRCode(info);
        QRCodeManager _qRCodeManager = new QRCodeManager(app);
        final Procedure1<QRCodeManager> _function = new Procedure1<QRCodeManager>() {
          public void apply(final QRCodeManager it) {
            it.genPermTicket(qrcode);
            String _ticket = qrcode.getTicket();
            SqrCode.logger.info(_ticket);
          }
        };
        ObjectExtensions.<QRCodeManager>operator_doubleArrow(_qRCodeManager, _function);
        String _ticket = qrcode.getTicket();
        String _plus = ("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + _ticket);
        _xblockexpression = ExecGet.excuteGetImg(_plus, (info + ".jpg"));
      }
      _xtrycatchfinallyexpression = _xblockexpression;
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
        final Exception e = (Exception)_t;
        Object _xblockexpression_1 = null;
        {
          e.printStackTrace();
          SqrCode.logger.error("Failed to get the sql file from weixin");
          _xblockexpression_1 = null;
        }
        _xtrycatchfinallyexpression = ((File)_xblockexpression_1);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
    return _xtrycatchfinallyexpression;
  }
}
